﻿using System.Net;
using System.Windows;
using System.Windows.Media;

namespace Red.Toolkit.EngineLogsViewer
{
    /// <summary>
    /// Interaction logic for AttachWindow.xaml
    /// </summary>
    public partial class AttachWindow : Window
    {
        private Brush _oldBackground;
        private IPAddress _ipAddress;
        private int _port;

        public AttachWindow( Window ownerWindow )
        {
            Owner = ownerWindow;

            InitializeComponent();

            _oldBackground = _ipAddressText.Background;
        }

        public IPAddress IpAddress { get { return _ipAddress; } }
        public int Port { get { return _port; } }

        private void AttachButton_Click( object sender, RoutedEventArgs e )
        {
            _ipAddressText.Background = _oldBackground;
            _portText.Background = _oldBackground;

            if ( IPAddress.TryParse( _ipAddressText.Text, out _ipAddress ) == false )
            {
                _ipAddressText.Background = Brushes.Red;
                return;
            }

            if ( int.TryParse( _portText.Text, out _port ) == false )
            {
                _portText.Background = Brushes.Red;
                return;
            }

            Close();
        }

        private void CancelButton_Click( object sender, RoutedEventArgs e )
        {
            Application.Current.Shutdown();
        }
    }
}
